package com.jie.oss.utils;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 用于读取application.yml文件中的属性值的工具类
 * ps: 类似于尚筹网项目中创建的Properties类
 * @author XieZhiJie
 * @create 2020-10-07 13:14
 */
@Component
public class ConstantPropertiesUtils implements InitializingBean {

    @Value("${aliyun.oss.file.endpoint}")
    private String endpoint;

    @Value("${aliyun.oss.file.key-id}")
    private String keyId;

    @Value("${aliyun.oss.file.key-secret}")
    private String keySecret;

    @Value("${aliyun.oss.file.bucket-name}")
    private String bucketName;

    // 定义公开常量

    public static String END_POINT;
    public static String ACCESS_KEY_ID;
    public static String ACCESS_KEY_SECRET;
    public static String BUCKET_NAME;

    // 当注入属性值后, 以下方法会执行
    @Override
    public void afterPropertiesSet() {
        END_POINT = this.endpoint;
        ACCESS_KEY_ID = this.keyId;
        ACCESS_KEY_SECRET = this.keySecret;
        BUCKET_NAME = this.bucketName;
    }
}
